from abc import ABC, abstractmethod

# Component: 抽象构件
class Component(ABC):
    @abstractmethod
    def sampleOperation(self):
        pass

# ConcreteComponent: 具体构件
class ConcreteComponent(Component):
    def sampleOperation(self):
        print("ConcreteComponent operation")

# Decorator: 抽象装饰器
class Decorator(Component):
    def __init__(self, component: Component):
        self._component = component

    def sampleOperation(self):
        self._component.sampleOperation()

# ConcreteDecoratorA: 具体装饰器 A
class ConcreteDecoratorA(Decorator):
    def __init__(self, component: Component):
        super().__init__(component)

    def sampleOperation(self):
        print("ConcreteDecoratorA added behavior")
        super().sampleOperation()

# ConcreteDecoratorB: 具体装饰器 B
class ConcreteDecoratorB(Decorator):
    def __init__(self, component: Component):
        super().__init__(component)

    def sampleOperation(self):
        print("ConcreteDecoratorB added behavior")
        super().sampleOperation()

# Client: 客户端
class Client:
    def __init__(self, component: Component):
        self._component = component

    def execute(self):
        self._component.sampleOperation()

# Usage
if __name__ == "__main__":
    # 创建具体构件
    concrete = ConcreteComponent()

    # 创建装饰器并包装具体构件
    decoratorA = ConcreteDecoratorA(concrete)
    decoratorB = ConcreteDecoratorB(decoratorA)

    # 客户端使用装饰后的构件
    client = Client(decoratorB)
    client.execute()


    # 代码实现
    # ConcreteDecoratorB
    # added
    # behavior
    # ConcreteDecoratorA
    # added
    # behavior
    # ConcreteComponent
    # operation